import 'dart:io';

import 'package:fate_blind_box/network/http_config.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'WebView.dart';

class AgreenDialog extends Dialog {
  const AgreenDialog({super.key});
  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final screenWidth = size.width;
    // final screenHeight = size.height;
    return Center(
      child: Container(
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(15)),
        ),
        height: 350,
        width: screenWidth * 0.8,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // 头像
            Container(
                margin: const EdgeInsets.only(top: 10),
                child: Center(
                    child: GestureDetector(
                  onTap: () {},
                  child: Stack(
                    children: [
                      ClipOval(
                          child: Image.asset("images/ic_agreenApp.png",
                              width: 80, height: 80, fit: BoxFit.cover)),
                    ],
                  ),
                ))),
            // tip
            Container(
                margin: const EdgeInsets.only(top: 20),
                child: Text(
                  "欢迎使用偶都肆商圈APP",
                  style: TextStyle(color: Colors.black, fontSize: 22),
                )),
            Container(
              margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
              child: Center(
                  child: Text.rich(TextSpan(children: [
                TextSpan(
                  text: "在你使用都肆商圈APP前，请认真阅读并了解",
                  style:
                      const TextStyle(color: Color(0xFF3A3A3A), fontSize: 14),
                  recognizer: TapGestureRecognizer()..onTap = () {},
                ),
                TextSpan(
                  text: "《隐私协议》",
                  style:
                      const TextStyle(color: Color(0xFF7F69D9), fontSize: 14),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (BuildContext context) {
                        return const Browser(
                            '隐私协议', '${HttpConfig.baseUrl}priva');
                      }));
                    },
                ),
                TextSpan(
                  text: "和",
                  style:
                      const TextStyle(color: Color(0xFF3A3A3A), fontSize: 14),
                  recognizer: TapGestureRecognizer()..onTap = () {},
                ),
                TextSpan(
                  text: "《服务协议》",
                  style:
                      const TextStyle(color: Color(0xFF7F69D9), fontSize: 14),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (BuildContext context) {
                        return const Browser(
                            '服务协议', '${HttpConfig.baseUrl}serv');
                      }));
                    },
                ),
                TextSpan(
                  text: "点击同意即可表示你已阅读并同意全部条款",
                  style:
                      const TextStyle(color: Color(0xFF3A3A3A), fontSize: 14),
                  recognizer: TapGestureRecognizer()..onTap = () {},
                ),
              ]))),
            ),
            Container(
              // width: 300,
              margin: const EdgeInsets.only(left: 10, right: 10, top: 14),

              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  InkWell(
                      onTap: () {
                        exit(0);
                      },
                      child: Container(
                        width: 98,
                        height: 30,
                        decoration: const BoxDecoration(
                          color: Color(0xFFF7F7F7),
                          borderRadius: BorderRadius.all(Radius.circular(5)),
                        ),
                        alignment: Alignment.center,
                        child: Text(
                          "拒绝",
                          style: TextStyle(
                            fontSize: 16,
                            color: Color(0xFF777777),
                          ),
                        ),
                      )),
                  InkWell(
                      onTap: () {
                        Provider.xieyi = 'xiyi';
                        Navigator.pop(context);
                        // Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) => const AppMain()), (route) => route == null);
                      },
                      child: Container(
                        width: 98,
                        height: 30,
                        decoration: const BoxDecoration(
                          color: Color(0xFFB6A2EE),
                          borderRadius: BorderRadius.all(Radius.circular(5)),
                        ),
                        alignment: Alignment.center,
                        child: const Text(
                          "同意",
                          style: TextStyle(fontSize: 16, color: Colors.white),
                        ),
                      )),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  static showUpdateDialog(BuildContext context) {
    return showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return const WillPopScope(
              child: AgreenDialog(), onWillPop: _onWillPop);
        });
  }

  static Future<bool> _onWillPop() async {
    return false;
  }
}
